Component({
  mixins: [],
  data: {
    listData1: [],
    page: 1,
    pagesize: 10,
    shop_total: '',
    total2: 0,
    total3: 0,
    modals1: false,
    listM: false,
    appList:[], //cd端小程序列表
    name:'',
    icon:'https://ossgw.alicdn.com/taobao-miniapp/img/79fa7f50c735f5b4ce07bd729f17fa38.png',
    clients:'taobao',
    description:'',
  },
  props: {},
  didMount() {
    this.tplQueryapp()
  },
  didUpdate() { },
  didUnmount() { },
  methods: {
    //关闭模态框
    closeModel(e) {
      var name = e.currentTarget.dataset.name;
      this.setData({ [name]: false });
    },
    openModel(e) {
      var name = e.currentTarget.dataset.name;
      this.setData({ [name]: true });
    },
    /**
     * 店铺优惠券
     */
    handleSubmit1() {
      if (!this.data.name) {
        my.alert({ content: '优惠券名称不能为空!' });
        return false;
      }
      if (!this.data.item) {
        my.alert({ content: '请设置一个发放数量!' });
        return false;
      }
      if (!this.data.condition) {
        my.alert({ content: '请设置使用门槛!' });
        return false;
      }
      if (!this.data.user_item) {
        my.alert({ content: '请设置每人限量!' });
        return false;
      }
      //my.alert({ content: JSON.stringify(this.data) });
      var apiurl = 'App.ShopRedsInfos.SaveUserCoupon';
      var params = {
        "name": this.data.name,
        "item": this.data.item,
        'start_time': this.data.selectTime[0],
        'end_time': this.data.selectTime[1],
        "denominations": this.data.denominations,
        "user_item": this.data.user_item,
        "condition": this.data.condition
      };
      var app = getApp();
      var self = this;
      app.xdapis(apiurl, params, function (e) {
        my.hideLoading();
         self.setData({
          modals1:false
        })
        self.getShopCouponList(1)
        my.alert({ title: '店铺优惠券创建成功!' });
      });
    },
   
    /** 获取实物礼品列表 */
    getKindList(pageNum) {
      var apiurl = 'App.ShopRedsInfos.GetInKind';
      var params = {
        "page": pageNum,
        "pagesize": this.data.pagesize,
      };
      var app = getApp();
      var self = this;
      app.xdapis(apiurl, params, function (e) {
        my.hideLoading();
        self.setData({
          listData3: e.list,
          total3: e.page_info.total
        });
      });
    },
    //店铺翻页
    pageShop(current){
      this.getShopCouponList(current.detail.value);
    },
    onChange(e) {
      let {
        detail: { value },
        currentTarget: { dataset }
      } = e;
      let { name } = dataset;
      console.log(name + ' onChange:', value);
      this.setData({ [name]: value });
    },
    /**
     * 实例化消费者小程序
     */
    tplInstantiate() {
      var that = this;
      if (!that.data.name) {
        my.alert({ content: '模板名称不能为空!' });
        return false;
      }
      if (!that.data.icon) {
        my.alert({ content: '模板图标地址不能为空!' });
        return false;
      }
      if (!that.data.description) {
        my.alert({ content: '模板描述不能为空!' });
        return false;
      }
      var apiurl = "taobao.miniapp.template.instantiate";
      var params = { 
        'clients': that.data.clients, 
        'name': that.data.name, 
        'template_id': '3000000002156421',
         ext_json: { "sellerNick": "浪子arvin", "user_id": '15' },
        'template_version': '0.0.4', 
        'appkey': '28272010', 
        'description': that.data.description, 
        'icon': that.data.icon
      };
      // my.alert({ title: JSON.stringify(params) });     
      var app = getApp();
      app.xdapiTop(apiurl, params, function (res) {
        my.hideLoading();
        that.setData({
          modals1:false,
          name:'',
          description:'',
        })
        that.tplQueryapp();//关闭弹框，刷新列表数据
        my.alert({ content: '模板生成成功!' });
        // my.alert({ title: JSON.stringify(res) });
      });
    },
    /**
     * 更新C端小程序
     */
    tplUpdate() {
      var app = getApp();
      var that = this;
      var apiurl = "taobao.miniapp.template.updateapp";
      var params = { 'clients': 'taobao', 'id': '3000000003068463', 'template_id': '3000000002156421', 'template_version': '0.0.4', ext_json: { "sellerNick": "浪子arvin", "user_id": '15' } };
      app.xdapiTop(apiurl, params, function (res) {
        my.hideLoading();
        my.alert({ title: JSON.stringify(res) });
      });
    },
    /**
     * 上线C端小程序
     */
    tplOnlineapp() {
      var app = getApp();
      var that = this;
      var apiurl = "taobao.miniapp.template.onlineapp";
      var params = { 'clients': 'taobao', 'app_id': '3000000003068463', 'template_id': '3000000002156421', 'template_version': '0.0.4','app_version':'0.0.1'};
      app.xdapiTop(apiurl, params, function (res) {
        my.hideLoading();
        my.alert({ title: JSON.stringify(res) });
      });
    },
    /**
     * 查询C端小程序
     */
    tplQueryapp(){
      var app = getApp();
      var that = this;
      var apiurl = "taobao.miniapp.template.queryapp";
      var params = { 'page_size': '20', 'page_num': '1', 'template_id': '3000000002156421'};
      app.xdapiTop(apiurl, params, function (res) {
        my.hideLoading();
        // my.alert({ title: JSON.stringify(res) });
        // my.alert({ title: JSON.stringify(res.all_version_infos) });
        that.setData({
          appList:res.all_version_infos
        });
      });
    },
    instantiate1() {
      var app = getApp();
      var that = this;
      var apiurl = "App.ShopRedsMiniApp.Instantiate";
      var params = { 'clients': 'taobao', 'name': '店铺红人', 'template_id': '3000000002156421', 'template_version': '0.0.4', 'appkey': '28272010', 'description': '店铺红人-短视频信息流为店铺提流', 'icon': 'https://ossgw.alicdn.com/taobao-miniapp/img/7eb7be64801658c35bce1df108465c5f.png' };
      app.xdapis(apiurl, params, function (res) {
        my.hideLoading();
        my.alert({ title: JSON.stringify(res) });
      });
    },
  }

});
